package kit.edu.lego.gruppe3.levels.line;

import kit.edu.lego.gruppe3.ComponentsRepository;
import kit.edu.lego.gruppe3.levels.LevelSelector;
import kit.edu.lego.gruppe3.sensors.Scanner;
import lejos.robotics.navigation.DifferentialPilot;
import lejos.robotics.subsumption.*;

public class followObstacle implements Behavior
{

	private DifferentialPilot robot = ComponentsRepository.getInstance()
			.getRobotPilot();

	@Override
	public void action() {
		robot.setTravelSpeed(10);
		robot.forward();
		while (robot.isMoving())
			if (ComponentsRepository.getInstance().getLightSensor().readValue() > ComponentsRepository.LIGHT_TRASHOLD) {
				ComponentsRepository.evadeObstacle = false;
				robot.stop();
				robot.rotate(50);
				return;
			}
		if(Scanner.getRangeAt(90, true) >= 20	|| Scanner.getRangeAt(90, true) < 14) return;
	}

	@Override
	public void suppress() {

	}

	@Override

	public boolean takeControl() {
		return LevelSelector.getInstance().isLine()
				&& ComponentsRepository.evadeObstacle
				&& Scanner.getRangeAt(90, true) <= 20
				&& Scanner.getRangeAt(90, true) > 14;


	}
}
